// 1. 引入 axios
import axios, { type AxiosInstance } from 'axios'

import headerObj from './header'

import type { IParams, IHeaders } from '../type/index'
// 2. 创建 实例

const request: AxiosInstance = axios.create({
  baseURL: 'https://m.maizuo.com',
  timeout: 30000
})

//请求 拦截器

request.interceptors.request.use(
  (config) => config,
  (err) => err
)

// 响应 拦截器

request.interceptors.response.use(
  (config) => config,
  (err) => err
)

export function getApi(params: IParams, key: IHeaders) {
  return request.get('/gateway', {
    params,
    headers: {
      ...headerObj[key]
    }
  })
}

// const getHotMovieList = (params) => getApi(params, 'hot')
